﻿//uses jquery

var kavadenn = kavadenn || {};

kavadenn.NotificationManager = function() {
}

kavadenn.NotificationManager.prototype.showFacebookConnectionNotification = function(message, onConnectClick) {
    this.closeFacebookConnectionNotification();
    $("body").append(this._buildFacebookNotification(message, onConnectClick));
}

kavadenn.NotificationManager.prototype.closeFacebookConnectionNotification = function(message) {
    $("#facebookNotificationPanel").remove();
}

kavadenn.NotificationManager.prototype.showErrorNotification = function(message) {
    this.closeErrorNotification();
    $("body").append(this._buildErrorNotification(message));
}

kavadenn.NotificationManager.prototype.closeErrorNotification = function(message) {
    $("#errorNotificationPanel").remove();
}

kavadenn.NotificationManager.prototype._buildErrorNotification = function(message) {
    return jQuery("<div>").attr("id", "errorNotificationPanel").html(message);
}

kavadenn.NotificationManager.prototype._buildFacebookNotification = function(message, onConnectClick) {

    /*
    <div id="facebookNotificationPanel">
    <div class="iconWrapper">
    <img width="32px" height="32px" src="/static/img/facebook.png" />
    </div>
    <div class="contentWrapper">
    Kavadenn marche mieux avec Facebook. <a href="#">Connectez vous</a> avec votre compte. 
    <a href="#" style="float:right;"><img border="0" src="/static/img/close.png" /></a>
    </div>
    </div>
    */

    var panel = jQuery('<div>').attr('id', 'facebookNotificationPanel').
                append(jQuery('<div>').attr('class', 'iconWrapper').append('<img width="32px" height="32px" src="/static/img/facebook.png" />')).
                append(jQuery("<div>").attr("class", "contentWrapper").
                        append(message + ' <a href="#" class="action">Connectez vous avec votre compte Facebook</a>').
                        append('<a href="#" class="close" style="float:right;"><img border="0" src="/static/img/close.png" /></a>')
                );

    if (onConnectClick) {
        panel.find(".action").click(onConnectClick);
    }

    panel.find(".close").click(function() {
        $('#facebookNotificationPanel').remove();
    });

    return panel;
}
